<?php
/*
	账户支付
	管理端支付接口
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	cfc('core')->checklogin();
	if(!$_RQ['id']){
		exi('没有找到该题库，请重新选择！','error','jy_lineks/index/');
	}
	$item=pdo_get('jy_lineks_tiku_zu',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	$this->model('model')->check_iscard($item);
	$this->model('model')->check_isguoqi($item);
	$return['item']=$item;
	$params=array('uniacid'=>$_SESSION['uniacid'],'zu_id'=>$_RQ['id']);
	if($_RQ['type']){
		$params['type']=$_RQ['type'];
		$return['typetitle']=$this->ti_types[$_RQ['type']];
	}
	$return['cards']=pdo_getall('jy_lineks_tiku',$params,array('id'));
	$return['allnum']=count($return['cards']);
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['remark'],
		'link'=>custom_url('jy_lineks/lianxi//id='.$item['id'],true),
		'imgUrl'=>ATTACHMENT_URL.$item['image'],
	);
	set_html('title',$item['title']);
	$this->session('zu_id',$_RQ['id']);
	$return['params']=array('zu_id'=>$_RQ['id'],'page'=>1,'type'=>intval($_RQ['type']));
	$return['danan_key']=$this->danan_key;
	exi($return);
}
if($_RQ['op']=='list'){
	$return['params']=array('zu_id'=>$this->session('zu_id'));
	$params=array('uniacid'=>$_SESSION['uniacid'],'zu_id'=>$this->session('zu_id'));
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(intval($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=intval($_RQ['type']);
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 1;
	}
	$total='';
	$list=pdo_getslice('jy_lineks_tiku',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$v){
			$v['xuanxiang']=json_decode($v['xuanxiang'],true);
			$v['images']=json_decode($v['images'],true);
			$like=pdo_get('jy_lineks_like',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ti_id'=>$v['id']),'id');
			$v['islike']=$like['id']?1:0;
			$v['typetitle']=$this->ti_types[$v['type']];

		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='like'){
	$postdata=get_postdata();
	$id=$postdata['id'];
	$like=pdo_get('jy_lineks_like',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ti_id'=>$id),'id');
	if($like['id']){
			pdo_delete('jy_lineks_like',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ti_id'=>$id));
			exi('取消成功');
	}else{
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'ti_id'=>$id,
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_lineks_like',$insert);
			exi('收藏成功');
	}
}
if($_RQ['op']=='upxuetimes'){
	$postdata=get_postdata();
	if($postdata){
		$this->model('model')->up_xuetimes($postdata);
	}
	exi('success');
}